package com.hsav.kcxb.fragment.setting;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hsav.kcxb.R;
import com.hsav.kcxb.view.CustomDialog;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link CacheFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class CacheFragment extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private ImageView mBackImg;
    private TextView mTitleTx;
    private RelativeLayout mClearPicLayout;
    private RelativeLayout mClearPlayLayout;
    private RelativeLayout mClearRecordLayout;
    private CustomDialog mCustomDialog;


    public CacheFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment CacheFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static CacheFragment newInstance(String param1, String param2) {
        CacheFragment fragment = new CacheFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.frag_clear_cache,container,false);
        initView(rootView);
        return rootView;
    }

    private void initView(View rootView) {
        mBackImg = (ImageView)rootView.findViewById(R.id.iv_top_back);
        mBackImg.setVisibility(View.VISIBLE);

        mTitleTx = (TextView)rootView.findViewById(R.id.tv_top_title);
        mTitleTx.setText("清除缓存");

        mClearPicLayout = (RelativeLayout)rootView.findViewById(R.id.rl_cache_img);
        mClearPicLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mCustomDialog == null){
                    mCustomDialog = new CustomDialog();
                }
                if(mCustomDialog.isVisible()){
                    mCustomDialog.dismiss();
                }
                mCustomDialog.setContentStr("确认要清空图片缓存吗");
                mCustomDialog.setOnClickListener(new CustomDialog.OnClickHandler() {
                    @Override
                    public void onCancelClick() {
                        Toast.makeText(getActivity(),"取消",Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onOkClick() {
                        Toast.makeText(getActivity(),"确定清除",Toast.LENGTH_LONG).show();
                    }
                });
                mCustomDialog.show(getFragmentManager(),"clear cache title");
            }
        });

        mClearPlayLayout = (RelativeLayout)rootView.findViewById(R.id.rl_cache_play);
        mClearPlayLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mCustomDialog==null){
                    mCustomDialog = new CustomDialog();
                }
                mCustomDialog.setContentStr("是否清除播放缓存");
                mCustomDialog.setOnClickListener(new CustomDialog.OnClickHandler() {
                    @Override
                    public void onCancelClick() {

                    }

                    @Override
                    public void onOkClick() {

                    }
                });
                mCustomDialog.show(getFragmentManager(),"clear play cache");
            }
        });
        mClearRecordLayout = (RelativeLayout)rootView.findViewById(R.id.rl_cache_record);
        mClearRecordLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mCustomDialog==null){
                    mCustomDialog = new CustomDialog();
                }
                mCustomDialog.setContentStr("确认清除本地录音？");
                mCustomDialog.setOnClickListener(new CustomDialog.OnClickHandler() {
                    @Override
                    public void onCancelClick() {
                    }

                    @Override
                    public void onOkClick() {

                    }
                });
                mCustomDialog.show(getFragmentManager(),"record");
            }
        });


    }

}
